<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>无标题文档</title>
    <link href="../../css/style.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="../../js/jquery.js"></script>
    <script type="text/javascript" src="../../js/purchase/purchase/orderAdd.js"></script>

    <script>
        var clickNum = 1;
        var danjia = 0;
        var shuliang = 0;
        var zonjia = 0;
        var zonjiaRes = 0;
        var zonjiaFlag = 0;

        // function myBlur1() {
        //     danjia = $(".shuliang").val();
        //     if (danjia != 0 && shuliang != 0) {
        //         zonjia = parseInt(danjia) * parseInt(shuliang);
        //         $(".zonjia").val(zonjia);
        //     }
        // }
        //
        // function myBlur2() {
        //     shuliang = $(".danjia").val();
        //     if (danjia != 0 && shuliang != 0) {
        //         zonjia = parseInt(danjia) * parseInt(shuliang);
        //         $(".zonjia").val(zonjia);
        //     }
        // }

        // myBlur3();


        function myBlur3() {
            // var mouseout = $(".zonjia").mouseout();
            // console.log("mouseout: " + mouseout)

            // $(".zonjia").mouseout(function (){
            //     cur03=$(this)
            //     // $()
            // })
            // shuliang = $("#shuliang").val();
            // if (danjia != 0 && shuliang != 0) {
            //     zonjia = danjia * shuliang;
            //     $(".z").val(zonjia);
            // }
            $(".danjia").blur(function () {
                let shuliangCode = $(this).parent().siblings().eq(5);
                shuliang = $(shuliangCode).children().val();
                // alert("数量"+shuliang);
                danjia = $(this).val();
                // alert("单价"+danjia);
                if (danjia != 0 && shuliang != 0) {
                    zonjia = parseInt(danjia) * parseInt(shuliang);
                    zonjiaFlag += 1;
                    $(this).parent().next().children().val(zonjia);
                } else {
                    zonjiaFlag += 1;
                    $(this).parent().next().children().val(0);
                }

                if (zonjiaFlag == 1){
                    zonjiaRes += zonjia / 2;
                    zonjiaFlag = 0;
                }else {
                    zonjia = 0;
                }

                $(".zonjiaRes").val(zonjiaRes);
            })
        }

        // 新增按钮
        function myClick() {
            clickNum++;
            var $ele = $('<tr class="trEle">');
            $ele.html("                <td>" + clickNum + "</td>>" +
                "<td>\n" +
                "                    <select class=\"brand\" onchange=\"queryType(this)\">\n" +
                "                        <option>请选择</option>\n" +
                "                        <option>联想</option>\n" +
                "                        <option>海尔</option>\n" +
                "                        <option>小米</option>\n" +
                "                    </select>\n" +
                "                </td>\n" +
                "                <td>\n" +
                "                    <select class=\"type\" onchange=\"queryModel(this)\">\n" +
                "                        <option>请选择</option>\n" +
                "                        <option>笔记本电脑</option>\n" +
                "                        <option>台式电脑</option>\n" +
                "                        <option>手机</option>\n" +
                "                    </select>\n" +
                "                </td>\n" +
                "                <td>\n" +
                "                    <select class=\"model\">\n" +
                "                        <option>请选择</option>\n" +
                "                        <option>X260</option>\n" +
                "                        <option>E470</option>\n" +
                "                        <option>T470</option>\n" +
                "                    </select>\n" +
                "                </td>\n" +
                "                <td>\n" +
                "                    <select name=\"company\">\n" +
                "                        <option th:each=\"type1:${connCPurchaseCon1s}\" th:selected=\"${type1.firmContent}=='发测试'\" th:value=\"${type1.firmContent}\"\n" +
                "                                th:text=\"${type1.firmContent}\" th:name=\"${type1.firmContent}\"></option>\n" +
                "                    </select>\n" +
                "                </td>\n" +
                "                <td><input name=\"count\" type=\"text\" class=\"shuliang\" onblur=\"myBlur3()\"\n" +
                "                           oninput=\"if(!/^[0-9]+$/.test(value)) value=value.replace(/\\D/g,'');if(value>5000)value=5000;if(value<1)value=1\">\n" +
                "                </td>\n" +
                "                <td>个</td>\n" +
                "                <td><input name=\"purchasePrice\" type=\"text\" class=\"danjia\" onblur=\"myBlur3()\">\n" +
                "                </td>\n" +
                "<!--                <td><input name=\"totalMoney\" type=\"text\" onmouseout=\"myBlur3()\" class=\"zonjia\"-->\n" +
                "                <td><input name=\"totalMoney\" type=\"text\" class=\"zonjia\"\n" +
                "                           oninput=\"if(!/^[0-9]+$/.test(value)) value=value.replace(/\\D/g,'');\"></td>");
            $('.tbodyT').append($ele);

        }

        function f1() {
            $(".buttonDelete").click(function () {
                $(".trEle").last().remove();
                console.log(clickNum)
                if (clickNum >= 2) {
                    clickNum--;
                }
            });
        }

        $(function () {
            f1()
        })

    </script>

</head>

<body>
<div class="place"><span>位置：</span>
    <ul class="placeul">
        <li>采购管理</li>
        <li>采购单管理</li>
        <li>添加</li>
    </ul>
</div>
<form action="/purchaseOrderManage/addPurchaseOrder" method="post">
    <div class="formbody">
        <div class="formtitle"><span>采购单信息</span></div>
        <ul class="forminfo">
            <li>
                <label>采购单编号</label>
                <input name="purchaseId" type="text" th:value="${conn.purchaseId}" readonly="readonly" class="roinput"/>
                <i>自动生成不能编辑</i>
            </li>
            <li>
                <label>采购时间</label>
                <input type="text"
                       th:value="${#dates.format(conn.purchaseTime, 'yyyy-MM-dd HH:mm')}" readonly="readonly"
                       class="roinput"/>
                <i>不能编辑</i>
            </li>
            <li>
                <label>创建人</label>
                <input type="text" readonly="readonly" class="roinput" value="管理员">
                <i>不能编辑</i>
            </li>
            <li>
                <label>审核状态</label>
                <input type="text" value="未审核" readonly="readonly" class="roinput"/>
                <input name="checkStatus" type="hidden" value="1"/>
                <i>初始状态，不能编辑</i>
            </li>
            <li>
                <label>总金额</label>
                <input type="text" readonly="readonly" class="roinput zonjiaRes"/>
                <i>自动运算，不能编辑</i>
            </li>
            <li>
                <input type="button" value="新增" class="smallbtn" onclick="myClick()"/>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <input type="button" value="删除" class="smallbtn buttonDelete"/>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <input type="submit" value="保存" class="smallbtn"/>
                &nbsp;&nbsp;&nbsp;&nbsp;
                <input type="button" value="返回" class="smallbtn" onclick="window.history.go(-1);"/>

            </li>
        </ul>
        <table class="tablelist">
            <thead>
            <tr>
                <th>序号</th>
                <th>品牌</th>
                <th>类型</th>
                <th>型号</th>
                <th>厂商</th>
                <th>数量</th>
                <th>单位</th>
                <th>单价</th>
                <th>金额</th>
            </tr>
            </thead>
            <tbody class="tbodyT">
            <tr class="tbodyTr">
                <td>1</td>
                <td>
                    <select class="brand" onchange="queryType(this)">
                        <option>请选择</option>
                        <option>联想</option>
                        <option>海尔</option>
                        <option>小米</option>
                    </select>
                </td>
                <td>
                    <select class="type" onchange="queryModel(this)">
                        <option>请选择</option>
                        <option>笔记本电脑</option>
                        <option>台式电脑</option>
                        <option>手机</option>
                    </select>
                </td>
                <td>
                    <select name="productIdName" class="model" onchange="getProductDetail(this)">
                        <option>请选择</option>
                        <option>X260</option>
                        <option>E470</option>
                        <option>T470</option>
                    </select>
                </td>
                <td>
                    <select>
                        <option th:each="type1:${connCPurchaseCon1s}" th:selected="${type1.firmContent}=='发测试'"
                                th:value="${type1.firmContent}"
                                th:text="${type1.firmContent}" th:name="${type1.firmContent}"></option>
                    </select>
                </td>
                <td><input name="count" type="text" class="shuliang" onblur="myBlur3()"
                           oninput="if(!/^[0-9]+$/.test(value)) value=value.replace(/\D/g,'');if(value>5000)value=5000;if(value<1)value=1">
                </td>
                <td>个</td>
                <td><input name="purchasePrice" type="text" class="danjia" onblur="myBlur3()">
                </td>
                <!--                <td><input name="totalMoney" type="text" onmouseout="myBlur3()" class="zonjia"-->
                <td><input name="totalMoney" type="text" class="zonjia"
                           oninput="if(!/^[0-9]+$/.test(value)) value=value.replace(/\D/g,'');"></td>
            </tr>
            </tbody>
        </table>
    </div>
</form>
<script type="text/javascript">
    $('.tablelist tbody tr:odd').addClass('odd');
</script>

</body>
</html>
